<template>
    <!-- 引入container布局 -->
    <el-container class="home-container">
         <!-- 头部 -->
        <el-header>
            <div>
                <img src="../assets/log.jpeg" alt class="logo_img" />
                <span>运动管理平台</span>
            </div>
            <el-button type="info" @click="loginOut">安全退出</el-button>
        </el-header>
         <!-- 下面主体 -->
        <el-container>
             <!-- 主体的左边侧边栏-->
            <el-aside :width="isCollapse?'64px':'200px'">
                <div class="toggle-button" @click="toggleCollapase">|||</div>
                <!--侧边栏菜单区 unique-opened="true" 只保持一个菜单展开
                     router(为true)开启路由  点击菜单会跳到index对应的路由
                     default-active  页面加载就是默认展示的路由
                -->
                <el-menu
                        background-color="#545c64"
                        text-color="#fff"
                        active-text-color="#ffd04b" :collapse="isCollapse"
                        :collapse-transition="false" :router="true" :default-active="activePath">
                    <el-submenu style="margin-left: -60px" :index="index+''" v-for="(item,index) in muenuList" :key="index" >
                        <!-- 一级菜单 -->
                        <template slot="title" >
                            <i :class="iconsObject[item.id]"></i>
                            <span>{{item.title}}</span>
                        </template>

                        <!-- 二级菜单 -->
                        <el-menu-item style="margin-left: 50px" :index="temp.path" :key="temp.id" v-for="(temp,tindex) in item.subMenuList" @click="Saveactive(temp.path)">
                            <template slot="title">
                                <i :class="iconsObject[temp.id]"></i>
                                <span>{{temp.title}}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>

            </el-aside>
             <!-- 主体的右边 用来内容显示 -->
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        data(){
            return {
                muenuList:[],  //菜单数组
                isCollapse:false,   //是否伸缩 true为不伸缩
                iconsObject: {  //图标数组
                    '100':'iconfont iconguanliyuan',
                    '200':'iconfont iconsport',
                    '101':'iconfont icondenglu',
                    '102':'iconfont iconmima',
                    '103':'iconfont iconsport',
                    '104':'iconfont iconshangpin',
                    '201':'iconfont iconshu',
                    '202':'iconfont iconkaluli',
                    '203':'iconfont iconshiwu',
                    '204':'iconfont icondenglu',
                },
                activePath : "/Welcome"
            }
        },
        name: "Home",
        methods:{
            loginOut:function () {
                this.$router.push("/login")
                window.sessionStorage.removeItem("user");  //删除浏览器session中的user
            },
            getMentList(){  //获取菜单的数组
                let  that = this;
                this.$axios.get("http://localhost:9000/menuList").then((response) =>{
                     that.muenuList = response.data;
                })
            },
            toggleCollapase(){  //伸缩左侧侧边栏
                 this.isCollapse = !this.isCollapse;
            },
            Saveactive(activepath){
                window.sessionStorage.setItem("activepath",activepath)
                this.activePath = activepath;
            }
        },
        // 页面加载执行
        created(){
            this.getMentList();
            this.activePath =  window.sessionStorage.getItem("activepath")

        }
    }
</script>

<style lang="less" scoped>
    .el-aside {
        background-color: #333744;
    }
    .el-main {
        background-color: #eaedf1;
    }
    .home-container {
        height: 100%;
    }

    .el-aside {
        background-color: #333744;
        .el-menu{
            border-right: none;// 对其右边框
        }
    }
    .el-header {
        background-color: #373d41;
        display: flex;
        justify-content: space-between;// 左右贴边
        padding-left: 0%;// 左边界
        align-items: center;// 水平
        color: #fff;
        font-size: 20px;
        > div { //左侧div加布局
            display: flex;
            align-items: center;
            span {
                margin-left: 15px;
            }
        }
    }

    .logo_img{
        width: 55px;
        height: 55px;
    }
    .toggle-button{
        background-color:#4A5064;
        font-size: 10px;
        line-height: 24px;
        color:#fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;// 显示鼠标指针为：小手
    }
</style>
